package com.bitdf.txing.product.controller;

import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.product.service.BrandService;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Lizhiwei
 * @date 2023/5/25 9:05:40
 * 注释：
 */
@RestController
@RequestMapping("${txing.request.path.product}")
public class CeshiController {

    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    RedissonClient redissonClient;
    @Autowired
    RBloomFilter bloomFilter;


    @RequestMapping("/hello/{text}")
    public String getCache(@PathVariable("text") String text){

//        bloomFilter.delete()

        String real = getReal();
        if (! bloomFilter.contains(text)) {
            return "布隆过滤器检测出： 缓存没有该数据，休想穿透缓存！";
        }
        return real;
    }


    public String getReal(){
        String text = redisTemplate.opsForValue().get("text");
        if (text == null) {
            text = "我爱你中华！";
            redisTemplate.opsForValue().set("text", text);
            bloomFilter.add("text");
        }
        return text;
    }
    @Autowired
    BrandService brandService;


    @RequestMapping("/ceshi/seata")
    public R testSeata(){
        brandService.testSeata();

        return R.ok();
    }
}
